import argparse
import subprocess


def run_command(cmd):
    """执行shell命令"""
    print(f"执行命令: {cmd}")
    result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
    if result.returncode != 0:
        print(f"发生错误: {result.stderr}")


def main():
    parser = argparse.ArgumentParser(description="临时移除insta-cmd依赖并推送分支")
    parser.add_argument("branch", help="要推送的分支名")
    args = parser.parse_args()

    run_command("cargo remove insta-cmd --dev")
    run_command(f"jj git push --allow-new -b {args.branch}")
    run_command(f"jj new {args.branch}")
    run_command("cargo add insta-cmd --dev")


if __name__ == "__main__":
    main()
